package com.auerdi.dialog;

import android.app.Dialog;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatDialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.auerdi.R;
import com.example.egghttp.EggLog.L;
import com.example.egghttp.retrofit.beans.banner.ItemList;
import com.example.egghttp.retrofit.beans.banner.SpecGoodsList;
import com.example.egghttp.retrofit.beans.goods.Product;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by highsixty on 2018/3/15.
 * mail  gaolulin@sunmi.com
 */

public class WantPinDialog extends AppCompatDialogFragment {


    Unbinder unbinder;

    private static Product mProduct;
    @BindView(R.id.tuanImg)
    ImageView tuanImg;
    @BindView(R.id.container)
    RelativeLayout container;
    @BindView(R.id.goPin)
    TextView goPin;


    private String mBuyType;
    ArrayList<ItemList> mSpecItemList = new ArrayList<>();
    private List<SpecGoodsList> specGoods;


    public static WantPinDialog newInstance(Product product, String buyType) {
        mProduct = product;
        WantPinDialog fragment = new WantPinDialog();
        Bundle args = new Bundle();
        args.putString("buyType", buyType);
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    public void onStart() {
        super.onStart();
        Dialog dialog = getDialog();

        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setCancelable(true);


        Window window = getDialog().getWindow();
        WindowManager.LayoutParams windowParams = window.getAttributes();
        windowParams.dimAmount = 0.6f;

        window.setAttributes(windowParams);
    }


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBuyType = (String) getArguments().get("buyType");
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.want_pin_dialog, container, false);
        L.d("hcia", "view:" + view);
        unbinder = ButterKnife.bind(this, view);
//        AnimationUtils.slideToUp(view);
//        ept.setOnClickListener(v -> {
//        });


        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        L.d("hcia", "mBuyType:" + mBuyType);


        container.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        goPin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CheckPinDialog.newInstance(mProduct, Product.GroupPrice).show(getFragmentManager(), "");

            }
        });



        ////                                            CheckPinDialog.newInstance(mProduct, Product.GroupPrice).show(getFragmentManager(), "")


//        Picasso.get().load(mProduct.getCover_img_url()).error(R.mipmap.logo).fit().placeholder(R.mipmap.logo).into(image);

//        RetrofitClient.getClient().create(AdService.class).collageSkuListLikePin(mProduct.getId())
//                .subscribeOn(Schedulers.newThread())
//                .observeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe
//                        (
//
//                                new Subscriber<BOb<ProdictCutDetailContainer>>() {
//                                    @Override
//                                    public void onCompleted() {
//                                    }
//
//                                    @Override
//                                    public void onError(Throwable e) {
//                                        L.d("hcia", "e:" + e);
//                                    }
//
//                                    @Override
//                                    public void onNext(BOb<ProdictCutDetailContainer> prodictCutDetailContainerBOb) {
//
//                                        specGoods = prodictCutDetailContainerBOb.getBody().getSpecGoodsList();
//                                        mProduct.setGood_spec(specGoods.get(0).getSpec_key());
//
//                                        L.d("hcia", "mProduct.getGood_spec():" + mProduct.getGood_spec());
//
//                                        List<SpecItemList> SpecItems = prodictCutDetailContainerBOb.getBody().getSpecItemList();
//
//                                        for (SpecItemList specItemList : SpecItems) {
//                                            mSpecItemList.add(specItemList.getItem_list().get(0));
//                                        }
//
//
//                                        Picasso.get().load(specGoods.get(0).getPic()).error(R.mipmap.epta).fit().placeholder(R.mipmap.epta).into(image);
//
//
//                                    }
//                                }
//                        );


    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
